﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for AZCpCarMoreDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class AZCpCarMoreDetailDB
    {
        public AZCpCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(AZCpCarMoreDetail azcpcarMoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemAZCp";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", azcpcarMoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarId", azcpcarMoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", azcpcarMoredetail.ProviderCompanyId);
            _sPara.Add("@AnnualPremium", azcpcarMoredetail.AnnualPremium);
            _sPara.Add("@TermPremium", azcpcarMoredetail.TermPremium);
            _sPara.Add("@Name", azcpcarMoredetail.Name);
            _sPara.Add("@IdentificationNo", azcpcarMoredetail.IdentificationNo);
            _sPara.Add("@Occupation", azcpcarMoredetail.Occupation);
            _sPara.Add("@ContactNo", azcpcarMoredetail.ContactNo);
            _sPara.Add("@OfficePhoneNo", azcpcarMoredetail.OfficePhoneNo);
            //_sPara.Add("@LicenseNo", azcpcarMoredetail.LicenseNo);
            _sPara.Add("@BeneficiaryName", azcpcarMoredetail.BeneficiaryName);

            _sPara.Add("@CarPlate", azcpcarMoredetail.CarPlate);
            _sPara.Add("@CarPlateProvince", azcpcarMoredetail.CarPlateProvince);
            _sPara.Add("@PresentAddress", azcpcarMoredetail.PresentAddress);
            _sPara.Add("@SubDistrict", azcpcarMoredetail.SubDistrict);
            _sPara.Add("@District", azcpcarMoredetail.District);
            _sPara.Add("@Province", azcpcarMoredetail.Province);
            _sPara.Add("@PostalCode", azcpcarMoredetail.PostalCode);
            _sPara.Add("@IsMailingAddressDiff", azcpcarMoredetail.IsMailingAddressDiff);
            _sPara.Add("@MailingAddress", azcpcarMoredetail.MailingAddress);
            _sPara.Add("@MailingSubDistrict", azcpcarMoredetail.MailingSubDistrict);
            _sPara.Add("@MailingDistrict", azcpcarMoredetail.MailingDistrict);
            _sPara.Add("@MailingProvince", azcpcarMoredetail.MailingProvince);
            _sPara.Add("@MailingPostalCode", azcpcarMoredetail.MailingPostalCode);
            _sPara.Add("@EngineNumber", azcpcarMoredetail.EngineNumber); //Sakthi on 24 Jun 2011
            _sPara.Add("@ChassisNumber", azcpcarMoredetail.ChassisNumber); //Sakthi on 24 Jun 2011
            //_sPara.Add("@IsRegisteredOwner", azcpcarMoredetail.IsRegisteredOwner); //Sakthi on 24 Jun 2011
            _sPara.Add("@IsCTPL", azcpcarMoredetail.IsCTPL);
            _sPara.Add("@CTPL", azcpcarMoredetail.CTPL);

            /*_sPara.Add("@No", azcpcarMoredetail.No);
            _sPara.Add("@Soi", azcpcarMoredetail.Soi);
            _sPara.Add("@Subzone", azcpcarMoredetail.Subzone);
            _sPara.Add("@Province", azcpcarMoredetail.Province);
            _sPara.Add("@Building", azcpcarMoredetail.Building);
            _sPara.Add("@Street", azcpcarMoredetail.Street);
            _sPara.Add("@District", azcpcarMoredetail.District);
            _sPara.Add("@PostalCode", azcpcarMoredetail.PostalCode);
            _sPara.Add("@IsDifferentAddress", azcpcarMoredetail.IsDifferentAddress);
            _sPara.Add("@NoMailing", azcpcarMoredetail.NoMailing);
            _sPara.Add("@SoiMailing", azcpcarMoredetail.SoiMailing);
            _sPara.Add("@SubzoneMailing", azcpcarMoredetail.SubzoneMailing);
            _sPara.Add("@ProvinceMailing", azcpcarMoredetail.ProvinceMailing);
            _sPara.Add("@BuildingMailing", azcpcarMoredetail.BuildingMailing);
            _sPara.Add("@StreetMailing", azcpcarMoredetail.StreetMailing);
            _sPara.Add("@DistrictMailing", azcpcarMoredetail.DistrictMailing);
            _sPara.Add("@PostalCodeMailing", azcpcarMoredetail.PostalCodeMailing);
            _sPara.Add("@VehicleNo", azcpcarMoredetail.VehicleNo);
            _sPara.Add("@EngineNo", azcpcarMoredetail.EngineNo);
            _sPara.Add("@ChassisNo", azcpcarMoredetail.ChassisNo);
            _sPara.Add("@VehicleColor", azcpcarMoredetail.VehicleColor);
            _sPara.Add("@VehicleProvince", azcpcarMoredetail.VehicleProvince);
            _sPara.Add("@PolicyStartDate", azcpcarMoredetail.PolicyStartDate);*/
            _sPara.Add("@PaymentOption", azcpcarMoredetail.PaymentOption);
            _sPara.Add("@PaymentType", azcpcarMoredetail.PaymentType);
            _sPara.Add("@PaymentBank", azcpcarMoredetail.PaymentBank); //Sakthi on 24 Jun 2011

            _sPara.Add("@OrderRefNoId", azcpcarMoredetail.OrderRefNoId);
            _sPara.Add("@OrderRefNo", azcpcarMoredetail.OrderRefNo);
            _sPara.Add("@PaymentStatus", azcpcarMoredetail.PaymentStatus);

            _sPara.Add("@QuoteRefNo", azcpcarMoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", azcpcarMoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", azcpcarMoredetail.ViewedDetailId);
            _sPara.Add("@CarResultId", azcpcarMoredetail.CarResultId);
            _sPara.Add("@Ninfo4", azcpcarMoredetail.Ninfo4); // For AgentId
            _sPara.Add("@Ninfo5", azcpcarMoredetail.Ninfo5); // Submission
            _sPara.Add("@Status", azcpcarMoredetail.Status);
            _sPara.Add("@Info1", azcpcarMoredetail.Info1);
            _sPara.Add("@Info2", azcpcarMoredetail.Info2);

            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public AZCpCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            AZCpCarMoreDetail _azcpcarMoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemAZCp";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _azcpcarMoredetail = new AZCpCarMoreDetail();
                    _azcpcarMoredetail = FillDataRecord(_dt);
                }
            }
            return _azcpcarMoredetail;
        }

        private AZCpCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            AZCpCarMoreDetail myCarMoreDetail = new AZCpCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.AnnualPremium = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremium"].ToString());
            myCarMoreDetail.TermPremium = Convert.ToSingle(myDataTable.Rows[0]["TermPremium"].ToString());
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            if (myDataTable.Rows[0]["IdentificationNo"] != null)
            {
                myCarMoreDetail.IdentificationNo = myDataTable.Rows[0]["IdentificationNo"].ToString();
            }
            myCarMoreDetail.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myCarMoreDetail.ContactNo = myDataTable.Rows[0]["ContactNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            //myCarMoreDetail.LicenseNo = myDataTable.Rows[0]["LicenseNo"].ToString();
            myCarMoreDetail.BeneficiaryName = myDataTable.Rows[0]["BeneficiaryName"].ToString();

            myCarMoreDetail.CarPlate = myDataTable.Rows[0]["CarPlate"].ToString();
            myCarMoreDetail.CarPlateProvince = myDataTable.Rows[0]["CarPlateProvince"].ToString();
            myCarMoreDetail.PresentAddress = myDataTable.Rows[0]["PresentAddress"].ToString();
            myCarMoreDetail.SubDistrict = myDataTable.Rows[0]["SubDistrict"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsMailingAddressDiff = Convert.ToBoolean(myDataTable.Rows[0]["IsMailingAddressDiff"].ToString());
            myCarMoreDetail.MailingAddress = myDataTable.Rows[0]["MailingAddress"].ToString();
            myCarMoreDetail.MailingSubDistrict = myDataTable.Rows[0]["MailingSubDistrict"].ToString();
            myCarMoreDetail.MailingDistrict = myDataTable.Rows[0]["MailingDistrict"].ToString();
            myCarMoreDetail.MailingProvince = myDataTable.Rows[0]["MailingProvince"].ToString();
            myCarMoreDetail.EngineNumber = myDataTable.Rows[0]["EngineNumber"].ToString(); //Sakthi on 24 Jun 2011
            myCarMoreDetail.ChassisNumber = myDataTable.Rows[0]["ChassisNumber"].ToString(); //Sakthi on 24 Jun 2011
            //myCarMoreDetail.IsRegisteredOwner = Convert.ToBoolean(myDataTable.Rows[0]["IsRegisteredOwner"].ToString());//Sakthi on 24 Jun 2011
            myCarMoreDetail.IsCTPL = Convert.ToBoolean(myDataTable.Rows[0]["IsCTPL"].ToString());
            myCarMoreDetail.CTPL = Convert.ToSingle(myDataTable.Rows[0]["CTPL"].ToString());

            /*myCarMoreDetail.No = myDataTable.Rows[0]["No"].ToString();
            myCarMoreDetail.Soi = myDataTable.Rows[0]["Soi"].ToString();
            myCarMoreDetail.Subzone = myDataTable.Rows[0]["Subzone"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.Building = myDataTable.Rows[0]["Building"].ToString();
            myCarMoreDetail.Street = myDataTable.Rows[0]["Street"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsDifferentAddress = Convert.ToBoolean(myDataTable.Rows[0]["IsDifferentAddress"].ToString());
            myCarMoreDetail.NoMailing = myDataTable.Rows[0]["NoMailing"].ToString();
            myCarMoreDetail.SoiMailing = myDataTable.Rows[0]["SoiMailing"].ToString();
            myCarMoreDetail.SubzoneMailing = myDataTable.Rows[0]["SubzoneMailing"].ToString();
            myCarMoreDetail.ProvinceMailing = myDataTable.Rows[0]["ProvinceMailing"].ToString();
            myCarMoreDetail.BuildingMailing = myDataTable.Rows[0]["BuildingMailing"].ToString();
            myCarMoreDetail.StreetMailing = myDataTable.Rows[0]["StreetMailing"].ToString();
            myCarMoreDetail.DistrictMailing = myDataTable.Rows[0]["DistrictMailing"].ToString();
            myCarMoreDetail.PostalCodeMailing = myDataTable.Rows[0]["PostalCodeMailing"].ToString();
            myCarMoreDetail.VehicleNo = myDataTable.Rows[0]["VehicleNo"].ToString();
            myCarMoreDetail.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCarMoreDetail.ChassisNo = myDataTable.Rows[0]["ChassisNo"].ToString();
            myCarMoreDetail.VehicleColor = myDataTable.Rows[0]["VehicleColor"].ToString();
            myCarMoreDetail.VehicleProvince = myDataTable.Rows[0]["VehicleProvince"].ToString();
            myCarMoreDetail.PolicyStartDate = Convert.ToDateTime(myDataTable.Rows[0]["PolicyStartDate"].ToString());*/

            myCarMoreDetail.PaymentOption = myDataTable.Rows[0]["PaymentOption"].ToString();
            myCarMoreDetail.PaymentType = myDataTable.Rows[0]["PaymentType"].ToString();
            myCarMoreDetail.PaymentBank = myDataTable.Rows[0]["PaymentBank"].ToString();//Sakthi on 24 Jun 2011
            myCarMoreDetail.QuoteRefNo = myDataTable.Rows[0]["QuoteRefNo"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.CarResultId = Convert.ToInt64(myDataTable.Rows[0]["CarResultId"].ToString());
            if (myDataTable.Rows[0]["Ninfo4"] != null)
            {
                myCarMoreDetail.Ninfo4 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo4"].ToString());
            }
            if (myDataTable.Rows[0]["Ninfo5"] != null)
            {
                myCarMoreDetail.Ninfo5 = Convert.ToInt32(myDataTable.Rows[0]["Ninfo5"].ToString());
            }
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());


            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceTHSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

        public Int64 CheckConfirmStatus(Int64 CarId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCheckUserConfirmStatus";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarId", CarId);
            _sPara.Add("@ResultType", ResultType);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

    }
}